package com.example.hsh.homefragment.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.SparseArray;

import com.example.hsh.homefragment.fragment.ContentListFragment;
import com.example.hsh.homefragment.fragment.TestFragment;


/**
 * Created by HSH on 2016/12/13.
 */

public class MainFragmentPagerAdapter extends FragmentPagerAdapter {

    private SparseArray<Fragment> fragments = new SparseArray<>();

    private String[] titles=new String[]{
        "test1",
        "test2",
        "test3",
        "test4"
    };

    public MainFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
        initFragment();
    }

    private void initFragment() {
        addFragment(ContentListFragment.newInstance(false, false), 0);
        addFragment(ContentListFragment.newInstance(false, false), 1);
        addFragment(ContentListFragment.newInstance(false, false), 2);
        addFragment(ContentListFragment.newInstance(false, false), 3);
    }

    public void addFragment(Fragment fragment,int fragmentId) {
        fragments.put(fragmentId, fragment);
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
